package leetcode.code0925;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public boolean isLongPressedName(String name, String typed) {
		char[] names = name.toCharArray();
		char[] types = typed.toCharArray();
		int i = 0, j = 0;
		int cur = 0, last = 0;
		while (i < names.length && j < typed.length()) {
			cur = names[i];
			if (types[j] == cur) {
				j++;
			} else {
				while (j < types.length && types[j] != cur) {
					if (types[j] != last) {
						return false;
					}
					j++;
				}
				if (j == types.length) {
					return false;
				}
				j++;
			}
			last = cur;
			i++;
		}
		if (i != names.length) {
			return false;
		}
		while (j < typed.length()) {
			if (types[j] != cur) {
				return false;
			}
			j++;
		}
		return true;
	}

	@Override
	public void debug1() {
		HelpDebug.compare(true, this.isLongPressedName("abcd", "aaabbbcccddd"));
		HelpDebug.compare(true, this.isLongPressedName("alex", "aaleexxxx"));
		HelpDebug.compare(true, this.isLongPressedName("alex", "aaleex"));
		HelpDebug.compare(false, this.isLongPressedName("ale", "aaleexxxx"));
		HelpDebug.compare(false, this.isLongPressedName("alex", "aalee"));
		HelpDebug.compare(false, this.isLongPressedName("saeed", "ssaaedd"));

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
